import socket,os
ip = socket.gethostbyname("www.baidu.com")
sock = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
sock.connect((ip,80))
sock.send("GET /img/baidu_sylogo1.gif HTTP/1.1\nHost:www.baidu.com\nAccept:*/*\nUser-Agent:Mozilla/4.0 (compatible; MSIE 5.00; Windows 98)\nConnection:Keep-Alive")
#sock.send("GET / HTTP/1.1\r\nHost: " + ip + "\r\nConnection:Close\r\n\r\n")
while 1:
	print ("Hello!")
	content = sock.recv(1024)
path   =   "web.gif" 
if os.path.exists(path):
	pass
else:
	fp = open(path,"wb")
	fp.close()

fp = open(path,"wb")
fp.write(content)
fp.close()
sock.close()